//
//  MYXPhotoItem.m
//  meiyinxiang
//
//  Created by apple on 2017/11/3.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

#import "MYXPhotoItem.h"
#import "STLoopProgressView.h"
@interface MYXPhotoItem ()

@end
@implementation MYXPhotoItem

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)awakeFromNib{
    [super awakeFromNib];
    self.imageView.layer.masksToBounds = YES;
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
}
+ (MYXPhotoItem *)loadNibWithPhotoItem{
    UINib *nib = [UINib nibWithNibName:@"MYXPhotoItem" bundle:[NSBundle mainBundle]];
    return  [[nib instantiateWithOwner:nil options:nil] lastObject];
}
- (IBAction)deleteBtn:(id)sender {
    //取消下载队列
   // self.uploadUrl = nil;
    [[[Http sharedInstance] uploadDataWithUrl:MYY_upload_URL withParams:nil constructingBodyWithBlock:nil completion:nil] cancel];
    if (self.tapDeleteBlock) {
        self.tapDeleteBlock([NSString stringWithFormat:@"%ld",self.tag]);
    }
}
- (void)uploadImgWithFinishBlock:(finishBlock)finishBlock{
        if (self.hidden == NO ) {
            [[Http sharedInstance] uploadImgDataWithUrl:MYY_upload_URL withParams:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                NSData *imgscreenData = UIImageJPEGRepresentation(self.imageView.image, 0.2);
                [formData appendPartWithFileData:imgscreenData name:@"file" fileName:@"pic.jpg" mimeType:@"image/jpg"];
            } progress:^(NSProgress * _Nonnull uploadProgress) {
                CGFloat progress = uploadProgress.completedUnitCount/uploadProgress.totalUnitCount;
                NSLog(@"上传进度 %f",progress);
            } completion:^(id data, NSError *error) {
    
                if (data) {
                    int  nRet = [[data objectForKey:@"status"] intValue];
                    if (nRet == 1) {
                        NSString *imagurl = data[@"data"];
                        NSLog(@"imgurl is %@",imagurl);
                        //self.imageView.image = self.itemImg;
                        self.uploadUrl = imagurl;
                        finishBlock(imagurl);
//                        NSString *imageData =[data objectForKey:@"data"][@"data"];
    
                    }
                }
    
    
            }];
        }else{
    
        }
}

@end
